package cst.a728hyl.startproject_728hyl;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a728hyl.startproject_728hyl.bean.Weatherinfo;
import cst.a728hyl.startproject_728hyl.listener.WeatherListener;
import cst.a728hyl.startproject_728hyl.model.WeatherModel;

public class MainActivity extends AppCompatActivity {
    private EditText city_edit;
    private Button btn_1;
    private TextView city_text;
    private TextView wd_text;
    private WeatherModel model;
    private WeatherListener listener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        city_edit = (EditText) findViewById(R.id.city_edit);
        btn_1 = (Button)findViewById(R.id.btn_1);
        city_text = (TextView)findViewById(R.id.city_text);
        wd_text = (TextView)findViewById(R.id.wd_text);
        listener=new WeatherListener() {
            @Override
            public void onResponse(Weatherinfo w) {
                city_text.setText(w.getCity());
                wd_text.setText(w.getTemp());
            }

            @Override
            public void onFail(String msg) {
                city_text.setText("解析错误");

            }
        };

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                model=new WeatherModel();
                model.getWeather(city_edit.getText().toString(),
                        listener);
            }
        });

    }
}
